﻿Public Class FrmAdmin
    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        If InvokeRequired Then
            Dim eventArgs() As Object = {sender, e}
            Invoke(New EventHandler(AddressOf OK_Click), _
              eventArgs)
            Return
        End If
        gEngineerPwd = GetSetting(My.Application.Info.Title, "Setting", "Engineer", "123")
        gAdminPwd = GetSetting(My.Application.Info.Title, "Setting", "Admin", "LNLON")
        Try
            Select Case cmbUsername.Text
                Case "Operator"

                Case "Engineer"
                    If PasswordTextBox.Text = gEngineerPwd Then
                        gPriority = 1

                        FrmMain.TextBox_OPID.Text = "Engineer"
                        FrmMain.TextBox_OPID.BackColor = Color.Lime
                    Else
                        MsgBox("用户名或密码错误,请重新输入! ")
                        gPriority = 0
                    End If
                Case "Admin"
                    If PasswordTextBox.Text = gAdminPwd Then
                        gPriority = 2

                        FrmMain.TextBox_OPID.Text = "Admin"
                        FrmMain.TextBox_OPID.BackColor = Color.Lime

                    Else
                        MsgBox("用户名或密码错误,请重新输入! ")
                        gPriority = 0
                    End If
                Case Else
                    MsgBox("用户名或密码错误,请重新输入! ")
                    Me.ShowDialog()
            End Select

            EnableMenu()

            Me.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Private Sub FrmAdmin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If cmbUsername.Items.Count = 0 Then
            cmbUsername.Items.Add("Engineer")
            cmbUsername.Items.Add("Admin")
        End If
        cmbUsername.SelectedIndex = 0
        PasswordTextBox.Clear()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            If MsgBox("Reset Password as Before !", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                SaveSetting(My.Application.Info.Title, "Setting", "Engineer", "123")
                SaveSetting(My.Application.Info.Title, "Setting", "Admin", "XC")
            Else
                Exit Sub
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Public Sub EnableMenu()
        Try
            Select Case gPriority
                Case 0
                    FrmProduct.ToolStrip1.Enabled = False
                    FrmProduct.ChToolStripMenuItem.Enabled = False
                    '       FrmMain.ToolStripButton17.Enabled = False
                    FrmMain.产品管理ProductToolStripMenuItem.Enabled = False
                    FrmMain.设置ToolStripMenuItem.Enabled = False
                    FrmMain.参数设置ToolStripMenuItem.Enabled = False
                    FrmMain.故障处理设置ToolStripMenuItem.Enabled = False

                    FrmMain.Panel1.Enabled = False
                    FrmMain.Button4.Enabled = False
                    FrmMain.Count_Clear.Enabled = False
                    FrmMain.ToolStripButton17.Enabled = False

                    FrmMain.Button_ClearSNQueue.Enabled = False
                Case 1
                    FrmProduct.ToolStrip1.Enabled = True
                    FrmProduct.ChToolStripMenuItem.Enabled = True
                    FrmMain.ToolStripButton17.Enabled = True
                    FrmMain.产品管理ProductToolStripMenuItem.Enabled = True
                    FrmMain.设置ToolStripMenuItem.Enabled = True
                    FrmMain.参数设置ToolStripMenuItem.Enabled = True
                    FrmMain.故障处理设置ToolStripMenuItem.Enabled = True
                 
                    FrmMain.Panel1.Enabled = True
                    FrmMain.Button4.Enabled = True
                    FrmMain.Count_Clear.Enabled = True
                    FrmMain.ToolStripButton17.Enabled = True

                    FrmMain.Button_ClearSNQueue.Enabled = True
                Case 2
                    FrmProduct.ToolStrip1.Enabled = True
                    FrmProduct.ChToolStripMenuItem.Enabled = True
                    FrmMain.ToolStripButton17.Enabled = True
                    FrmMain.产品管理ProductToolStripMenuItem.Enabled = True
                    FrmMain.设置ToolStripMenuItem.Enabled = False
                    FrmMain.参数设置ToolStripMenuItem.Enabled = False
                    FrmMain.故障处理设置ToolStripMenuItem.Enabled = False
                   
                    FrmMain.Panel1.Enabled = False
                    FrmMain.Button4.Enabled = False
                    FrmMain.Count_Clear.Enabled = False
                    FrmMain.ToolStripButton17.Enabled = False
                    FrmMain.Button_ClearSNQueue.Enabled = True
            End Select
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        FrmPwdChange.ShowDialog()
    End Sub
End Class
